package com.siyougame.app.aop;


import com.siyougame.app.WxUserEntity;
import com.siyougame.common.constant.ResponseCode;
import com.siyougame.common.exception.RRException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


/**
 * 系统日志，切面处理类
 *
 * @date 2017年3月8日 上午11:07:35
 */
@Slf4j
@Aspect
@Component
public class NeedMobileAspect {


    @Pointcut("@annotation(com.siyougame.app.annotation.NeedMobile)")
    public void logPointCut() {

    }

    @Before("logPointCut()")
    public void saveSysLog(JoinPoint joinPoint) {
        //参数值
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (arg instanceof WxUserEntity) {
                WxUserEntity wu = (WxUserEntity) arg;
                if (StringUtils.isBlank(wu.getMobile())) {
                    throw new RRException(ResponseCode.NO_MOBILE.getDesc(), ResponseCode.NO_MOBILE.getCode());
                }
            }
        }
    }

}
